<?php

namespace App\Index\Controller;

use App\Common\OneUI\_classes\Template;
use App\Common\UnitTool\Multiavatar;
use SinglePHP\BaseController;

use SinglePHP\Controller;
use SinglePHP\Db;

class Index extends BaseController
{
    public function index()
    {
        $this->assign('title', '测试View');
        $this->display();
        //        dump(Config::all());
        //        $res = Db::get('teacher', '*', [ 'id' => 1 ]);
        //        dump($res);

    }

    public function test()
    {
        $multiavatar = new Multiavatar();

        $avatarList = [];
        foreach (range(0, 15) as $part) {
            foreach ([ 'A', 'B', 'C' ] as $theme) {
                $part = strval($part);
                if (strlen($part) == 1) {
                    $part = '0' . $part;
                }
                // echo($part);
                // echo($theme);
                $avatarList[$part . '-' . $theme] = $multiavatar('asdf', null, [ "part" => $part, "theme" => $theme ]);
//                dump([ "part" => $part, "theme" => $theme ]);

            }
        }
//        $this->assign('avatarList', $avatarList);
//        $this->display();


        //
        // Deprecated (with __construct)
        //
        $avatarId = "Starcrasher";
        $multiavatar = new Multiavatar($avatarId, null, null);
        $array[] = ($multiavatar->svgCode);

        $avatarId = "Pandalion";
        $multiavatar = new Multiavatar($avatarId, true, null);
        $array[] = ($multiavatar->svgCode);

        $avatarId = "Starcrasher";
        $multiavatar = new Multiavatar($avatarId, null, array( "part" => "11", "theme" => "C" ));
        $array[] = ($multiavatar->svgCode);


        //
        // New version (with __invoke)
        //
        $multiavatar = new Multiavatar();

        // Basic test
        $array[] = ($multiavatar("Starcrasher", null, null));

        // Without the environment part
        $avatarId = md5(time());
        $array[] = ($multiavatar($avatarId, true, null));

        // Generate a specific version
        $array[] = ($multiavatar($avatarId, null, array( "part" => "11", "theme" => "C" )));

        // Generate a specific version
        $array[] = ($multiavatar($avatarId, null, array( "part" => "08", "theme" => "C" )));

        // Test transparency
        $array[] = ($multiavatar($avatarId, null, array( "part" => "02", "theme" => "B" )));

        // Test with integer
        $avatarId = 123456789;
        $array[] = ($multiavatar($avatarId, null, null));

        $avatarId = "a86f755add37fe0b649c";
        $array[] = ($multiavatar($avatarId, null, null));

        $avatarId = md5('lishiping');
        $array[] = ($multiavatar($avatarId, null, null));

        $this->assign('avatarList', $array);
        $this->display();
    }

    public function test1()
    {
        $this->display();
    }

    public function test3()
    {
        $one = new Template('OneUI', '4.8', '/static/OneUISource/src/assets');
        $avatarId = "a86f755add37fe0b649c";
        $multiavatar = new Multiavatar();


        $one->avatars = $multiavatar($avatarId, null, null);
        $this->assign('one', $one);
        $this->display();
    }

    public function avatars()
    {
        $avatarId = "a86f755add37fe0b649c";
        $multiavatar = new Multiavatar();

        echo $multiavatar($avatarId, null, null);
    }
}